package com.xinyues.gamemanager.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.xinyues.gamemanager.dao.entity.GmRole;
import com.xinyues.gamemanager.params.GmRoleParam;
import com.xinyues.gamemanager.service.CommonService;
import com.xinyues.gamemanager.service.GmRoleService;
import com.xinyues.gamemanager.vo.VoGmRole;
import com.xinyues.gamemanager.vo.VoRoleList;
/**
 * 
 * @ClassName: GmRoleController 
 * @Description: 角色管理
 * @author: wang guang shuai
 * @date: 2019年12月9日 下午9:24:32
 */
@RestController
@RequestMapping("/gm-role")
public class GmRoleController {
    @Autowired
    private GmRoleService gmRoleService;
    @Autowired
    private CommonService commonService;
    @GetMapping("getGmRole")
    public Object getGmRole(@RequestParam("page") int page, @RequestParam("rows") int rows, HttpServletRequest request) {
        List<GmRole> gmRoles = gmRoleService.getAllGmRole();
        List<VoGmRole> voGmRoles = gmRoleService.getVoGmRole(gmRoles);
        return commonService.responseTable(voGmRoles, voGmRoles.size());
    }
    @PostMapping("addGmRole")
    public Object addGmRole(@RequestBody GmRoleParam addGmRoleParam) {
        gmRoleService.addGmRole(addGmRoleParam);
        return commonService.response();
    }
    @PostMapping("deleteGmRole/{roleId}")
    public Object deleteGmRole(@PathVariable String roleId) {
        gmRoleService.deleteGmRole(roleId);
        return commonService.response();
    }
    @GetMapping("getRoleList")
    public Object getRoleList() {
        List<GmRole> gmRoles = gmRoleService.getAllGmRole();
        List<VoRoleList> voRoleLists = gmRoles.stream().map(r->{
            VoRoleList voRoleList = new VoRoleList();
            voRoleList.setId(r.getId());
            voRoleList.setText(r.getText());
            return voRoleList;
        }).collect(Collectors.toList());
        return voRoleLists;
    }
}
